import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class InquireBookManage {
    private Scanner sc=new Scanner(System.in);
    //查询图书
    public void home() throws SQLException, ClassNotFoundException {
        while(true) {
            menuInquireBookManage();
            int x = sc.nextInt();
            switch (x) {
                case 1://显示所有图书
                    showBook();
                    break;
                case 2://按书号查询
                    showBookById();
                    break;
                case 3://按书名查询
                    showBookByName();
                    break;
                case 4://按作者查询
                    showBookByAuthor();
                    break;
                case 5://按出版社查询
                    showBookByPress();
                    break;
                case 0://返回
                    break;
                default:
                    System.out.println("非法输入");
                    break;
            }
            if(x==0){
                break;
            }
        }
    }
    //显示所有图书
    public  void showBook() throws SQLException, ClassNotFoundException {
        Base ba=new Base();
        ResultSet re;
        System.out.println("-------图书--------");
        re=ba.getBook();
        if(re.isBeforeFirst()) {//判断非空
            while (re.next()) {
                System.out.print(re.getString("id") + "\t");
                System.out.print(re.getString("name") + "\t");
                System.out.print(re.getString("author") + "\t");
                System.out.print(re.getString("press") + "\t");
                System.out.print(re.getString("price") + "\t");
                System.out.println(re.getString("pressDate") + "\t");
            }
        }else{
            System.out.println("空");
        }
        //可以尝试做个翻页
        while(true){
            System.out.println("输入0，返回图书查询页面");
            if(sc.next().equals("0")){
                break;
            }else{
                System.out.println("非法输入");
            }
        }
    }
    //----以下未实现
    //按书号查询
    public void showBookById(){

    }
    //按书名查询
    public void showBookByName(){

    }
    //按作者查询
    public void showBookByAuthor(){

    }
    //按出版社查询
    public void showBookByPress(){

    }
    //菜单
    public void  menuInquireBookManage(){
        System.out.println("---------查询图书---------");
        System.out.println("请选择=>");
        System.out.println("1.显示所有图书 2.按书号查询");
        System.out.println("3.按书名查询   4.按作者查询");
        System.out.println("5.按出版社查询 0.返回");
    }
}
